package controllers

import (
	"CRMSystem/models"
)

type LatentCustomerController struct {
	MainController
}

// LatentCustomerList 潜在客户列表
func (c *LatentCustomerController) LatentCustomerList() {
	c.IfHasSession()
	var from int64
	var to int64
	currentPage, _ := c.GetInt64("currentPage")
	pageSize, _ := c.GetInt64("pageSize")
	from = (currentPage - 1) * pageSize
	to = currentPage * pageSize
	list, i := models.GetLatentCustomerListInformation(from, to)
	totalPage := i/pageSize + 1
	if i > 0 {
		c.Data["json"] = Status{Date: list, TotalPage: totalPage, ErrCode: POST_OK, Msg: "LatentCustomerList:success"}
		c.ServeJSON()
		c.StopRun()
	} else if currentPage > totalPage {
		c.Data["json"] = Status{ErrCode: GET_ERR, Msg: "Error"}
		c.ServeJSON()
		c.StopRun()
	} else {
		c.Data["json"] = Status{ErrCode: POST_ERR, Msg: "Error"}
		c.ServeJSON()
		c.Redirect("/page/err400", 302)
	}
}
